package com.ssm.subject.infra.basic.service.impl;

import com.alibaba.fastjson.JSON;
import com.ssm.subject.infra.basic.entity.SubjectCategory;
import com.ssm.subject.infra.basic.mapper.SubjectCategoryDao;
import com.ssm.subject.infra.basic.service.SubjectCategoryService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目分类(SubjectCategory)表服务实现类
 *
 * @author makejava
 * @since 2024-11-21 17:39:20
 */
@Service("SubjectCategoryService")
@Log4j2
public class SubjectCategoryServiceImpl implements SubjectCategoryService {
    @Resource
    private SubjectCategoryDao subjectCategoryDao;

    /**
     * 添加分类
     *
     * @param subjectCategory 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SubjectCategory subjectCategory) {
        if(log.isInfoEnabled()) {
            log.info("SubjectCategoryService.insert.subjectCategory:{}", JSON.toJSONString(subjectCategory));
        }
        return this.subjectCategoryDao.insert(subjectCategory);
    }

    /**
     * 更新分类
     *
     * @param subjectCategory 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SubjectCategory subjectCategory) {
        if(log.isInfoEnabled()) {
            log.info("SubjectCategoryService.update.subjectCategory:{}", JSON.toJSONString(subjectCategory));
        }
        return this.subjectCategoryDao.update(subjectCategory);
    }

    /**
     * 查询分类
     * @return
     */
    @Override
    public List<SubjectCategory> queryCategory(SubjectCategory subjectCategory) {
        List<SubjectCategory> subjectCategoryList = subjectCategoryDao.queryCategory(subjectCategory);
        if(log.isInfoEnabled()) {
            log.info("SubjectCategoryService.queryCategory.SubjectCategoryList:{}", JSON.toJSONString(subjectCategoryList));
        }
        return subjectCategoryList;
    }

    @Override
    public SubjectCategory queryById(Long categoryId) {
        return this.subjectCategoryDao.queryById(categoryId);
    }

    /**
     * 查询大分类下的题目数量
     * @param id
     * @return
     */
    @Override
    public Integer querySubjectCount(Long id) {
        return subjectCategoryDao.querySubjectCount(id);
    }
}
